package com.hospital.util;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;

/**
 * 常用方法
 */
public class JMyUtil {

	public static LocalDate nowDate = LocalDate.now();

	/**
	 * 天数差。传入小的。
	 */
	public static Long monthDifference1(Date date) {
		LocalDateTime otherdate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
		long MONTHSbetween = ChronoUnit.MONTHS.between(otherdate.toLocalDate(), nowDate);
		return MONTHSbetween;
	}

	/**
	 * 天数差。传入大的。
	 */
	public static Long monthDifference2(Date date) {
		LocalDateTime otherdate = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
		long MONTHSbetween = ChronoUnit.MONTHS.between(nowDate, otherdate.toLocalDate());
		return MONTHSbetween;
	}

	/**
	 * 判断字符串是否不为null和""
	 * 
	 * @return boolean
	 */
	public static boolean notEmpty(Object str) {
		if (str == null || "".equals(str)) {
			return false;
		}
		return true;
	}

	/**
	 * 判断字符串是否为null和""
	 * 
	 * @return boolean
	 */
	public static boolean isEmpty(Object str) {
		if (str == null || "".equals(str)) {
			return true;
		}
		return false;
	}

	/**
	 * 字符串转date
	 * 
	 * @condition 要求格式：yyyy-MM-dd
	 */
	public static Date formatStringToDate_yMd(String datestr) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(datestr);
		return date;
	}

	/**
	 * 字符串转date
	 * 
	 * @condition 要求格式：yyyy-MM-dd HH:mm:ss
	 */
	public static Date formatStringToDate_yMdHms(String datestr) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = sdf.parse(datestr);
		return date;
	}

	/**
	 * 获取当前时间，字符串格式
	 * 
	 * @return 返回格式：yyyy-MM-dd HH:mm:ss
	 */
	public static String getFormatNowTime() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String newTime = sdf.format(date);
		return newTime;
	}

	/**
	 * 获取当前时间，字符串格式
	 * 
	 * @return 返回格式：yyyy-MM-dd HH:mm:ss
	 */
	public static String getNowTime() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String newTime = sdf.format(date);
		return newTime;
	}

	/**
	 * 格式化long时间戳为字符串格式
	 * 
	 * @return 返回格式：yyyy-MM-dd HH:mm:ss
	 */
	public static String getFormatTime(long time) {
		Date date = new Date(time);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String newTime = sdf.format(date);
		return newTime;
	}

	/**
	 * 格式化long时间戳为字符串格式
	 * 
	 * @return 返回格式：yyyy-MM-dd HH:mm:ss
	 */
	public static String getNowTime(long time) {
		Date date = new Date(time);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String newTime = sdf.format(date);
		return newTime;
	}
}
